package com.webcamtracker.utils;

import com.webcamtracker.configuration.RootPref;
import com.webcamtracker.image.color.hsv.HSVColor;


public class Hit {
    private HSVColor color;
    private int hits = 0;
    public boolean changeColorOnHit = true;

    public Hit(HSVColor color) {
        this.color = color;
    }

    public Hit(HSVColor color, boolean changeColorOnHit) {
        this.color = color;
        this.changeColorOnHit = changeColorOnHit;
    }

    public void hit(HSVColor color) {
//        if (changeColorOnHit) {
//            this.color.setHue((color.getHue() + this.color.getHue()) / 2);
//            this.color.setSaturation((color.getSaturation() + this.color.getSaturation()) / 2);
//            this.color.setBrightness((color.getBrightness() + this.color.getBrightness()) / 2);
//        }
        hits++;
    }

    public HSVColor getColor() {
        return color;
    }

    protected void setHits(int hits) {
        this.hits = hits;
    }

    public int getHits() {
        return hits;
    }

    public float getPercentage(Hits hits) {
        int totalSamples = hits.getTotalSamples();
        int hit = getHits();
        if (totalSamples == 0) {
            return 0;
        }
        return (float) hit / totalSamples;
    }

    public boolean equals(Object obj) {
        Double value = RootPref.getColorPref().getDouble(RootPref.KEY_TRESHOLD, RootPref.DEF_VALUE_TRESHOLD);

        com.webcamtracker.image.Color color1 = ((Hit) obj).color;
        return color1.isSimilar(color, value);
    }


    public String toString() {
        return "Hit{" +
                "color=" + color +
                ", hits=" + hits +
                '}';
    }
}
